export default{
  namespaced:true,

//state数据
state:()=>({
  address:JSON.parse(uni.getStorageSync('address')||'{}'),
  token:uni.getStorageSync('token')||'',
  //用户的信息对象
  userinfo:JSON.parse(uni.getStorageSync('userinfo')||'{}'),
  redirectInfo:null
}),

//方法
mutations:{
  updateAddress(state,address){
    state.address = address
    //通过this.commit()方法，调用m_user模块下的saveAddresssToStorage方法将address 对象持久化存储到本地上
    this.commit('m_user/saveAddressToStorage')
  },
  saveAddressToStorage(state){
    uni.setStorageSync('address',JSON.stringify(state.address))
  },
    // 更新用户的基本信息
    updateUserInfo(state, userinfo) {
      state.userinfo = userinfo
      // 通过 this.commit() 方法，调用 m_user 模块下的 saveUserInfoToStorage 方法，将 userinfo 对象持久化存储到本地
      this.commit('m_user/saveUserInfoToStorage')
    },
  
    // 将 userinfo 持久化存储到本地
    saveUserInfoToStorage(state) {
      //json.stringfy转成字符串
      uni.setStorageSync('userinfo', JSON.stringify(state.userinfo))
    },
    updateToken(state,Token){
      state.token = token
      this.commit('m_user/saveTokenToStorge')
    },
    saveTokenToStorage(state){
      uni.setStorageSync('token',state.token)
    },
     // 更新重定向的信息对象
      updateRedirectInfo(state, info) {
        state.redirectInfo = info
      }
    
},

//数据包装器
getter:{ 
    addstr(state){
        if(!state.address.provinceName)return ''
        //拼接省市区详细地址的字符串并返回给用户
        return state.address.provinceName +state.address.cityName + state.address.countyName + state.address.detailInfo
      }},

}